<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { StaffList, checkStaff } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      comArr: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "正常", value: "1" },
        { label: "到期", value: "2" },
        { label: "禁用", value: "3" },
      ],
      queryData: {
        staff_status: "",
        enterprise_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    questCheck(data) {
      checkStaff(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
        }
      });
    },
    checkStatus(row, type) {
      if (type == 1) {
        ElMessageBox.confirm("确定恢复选择的员工账号吗?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let data = {
            staff_id: row.staff_id,
            staff_status: type,
          };
          this.questCheck(data);
        });
      } else {
        ElMessageBox.prompt("确定禁用选择的员工账号吗?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then((value) => {
          let data = {
            staff_id: row.staff_id,
            staff_status: type,
            jy_reason: value.value,
          };
          this.questCheck(data);
        });
      }
    },
    getData() {
      StaffList(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  async created() {
    this.comArr = await this.$getCate.getComList();
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>企业员工账号列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-select
                v-model="queryData.enterprise_name"
                filterable
                @change="getData"
                clearable
                placeholder="请输入企业名称"
              >
                <el-option
                  v-for="item in comArr"
                  :key="item.enterprise_id"
                  :label="item.enterprise_name"
                  :value="item.enterprise_name"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.staff_status"
                clearable
                @change="getData"
                placeholder="请选择账号状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="staff_user_mobile"
          show-overflow-tooltip
          label="账号"
        />
        <el-table-column
          prop="staff_user_name"
          show-overflow-tooltip
          label="姓名"
        />
        <el-table-column
          prop="enterprise_name"
          show-overflow-tooltip
          label="所属企业"
        />
        <el-table-column show-overflow-tooltip label="账号状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.staff_status == 1">正常</el-tag>
              <el-tag type="danger" v-if="row.staff_status == 2">禁用</el-tag>
              <el-tag type="info" v-if="row.staff_status == 3">已到期</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="jy_reason"
          show-overflow-tooltip
          label="禁用原因"
        />
        <el-table-column
          prop="create_time"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column
          prop="expiration_time"
          show-overflow-tooltip
          label="到期时间"
        />
        <el-table-column prop="Name" width="60" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="blueText ctrlText"
                @click="checkStatus(row, 1)"
                v-if="row.staff_status == 2"
              >
                恢复
              </div>
              <div
                v-if="row.staff_status == 1"
                @click="checkStatus(row, 2)"
                class="redText ctrlText"
              >
                禁用
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
